using System;
using System.Collections.Generic;
using System.Text;
using DDW.Collections;

namespace DDW
{
	public class ClassNode : BaseNode
	{
		private Modifier modifiers;
		public Modifier Modifiers
		{
			get { return modifiers; }
			set { modifiers = value; }
		}

		private IdentifierExpression name;
		public IdentifierExpression Name
		{
			get { return name; }
			set { name = value; }
		}

		private List<TypeNode> baseClasses;
		public List<TypeNode> BaseClasses
		{
			get { if (baseClasses == null) baseClasses = new List<TypeNode>(); return baseClasses; }
		}
	

		private NodeCollection<ConstantNode> constants;
		public NodeCollection<ConstantNode> Constants
		{
			get { if (constants == null) constants = new NodeCollection<ConstantNode>(); return constants; }
		}

		private NodeCollection<FieldNode> fields;
		public NodeCollection<FieldNode> Fields
		{
			get { if (fields == null) fields = new NodeCollection<FieldNode>(); return fields; }
		}

		private NodeCollection<PropertyNode> properties;
		public NodeCollection<PropertyNode> Properties
		{
			get { if (properties == null) properties = new NodeCollection<PropertyNode>(); return properties; }
			set { properties = value; }
		}

		private NodeCollection<ConstructorNode> constructors;
		public NodeCollection<ConstructorNode> Constructors
		{
			get { if (constructors == null) constructors = new NodeCollection<ConstructorNode>(); return constructors; }
			set { constructors = value; }
		}

		private NodeCollection<DestructorNode> destructors;
		public NodeCollection<DestructorNode> Destructors
		{
			get { if (destructors == null) destructors = new NodeCollection<DestructorNode>(); return destructors; }
			set { destructors = value; }
		}

		private NodeCollection<MethodNode> methods;
		public NodeCollection<MethodNode> Methods
		{
			get { if (methods == null) methods = new NodeCollection<MethodNode>(); return methods; }
			set { methods = value; }
		}

		private NodeCollection<IndexerNode> indexers;
		public NodeCollection<IndexerNode> Indexers
		{
			get { if (indexers == null) indexers = new NodeCollection<IndexerNode>(); return indexers; }
			set { indexers = value; }
		}

		private NodeCollection<EventNode> events;
		public NodeCollection<EventNode> Events
		{
			get { if (indexers == null) events = new NodeCollection<EventNode>(); return events; }
			set { events = value; }
		}

		//private NodeCollection<FieldNode> members;
		//public NodeCollection<FieldNode> Members
		//{
		//    get { return members; }
		//    set { members = value; }
        //}

		public override void ToSource(StringBuilder sb)
		{
			WriteLocalSource(sb, "class");
		}
        protected void WriteLocalSource(StringBuilder sb, string kind)
		{
			if (attributes != null)
			{
				attributes.ToSource(sb);
				this.NewLine(sb);
			}
			TraceModifiers(modifiers, sb);

			sb.Append(kind + " "); 
			name.ToSource(sb);	
			sb.Append(" ");

			if (baseClasses != null && baseClasses.Count > 1)
			{
				sb.Append(": ");
				string comma = "";
				foreach (TypeNode bcls in baseClasses)
				{
					sb.Append(comma);
					comma = ", ";
					bcls.ToSource(sb);					
				}
			}

			this.NewLine(sb);
			sb.Append("{");
			indent++;
			this.NewLine(sb);

			if(constants != null)
			{
				constants.ToSource(sb);
			}
			if(fields != null)
			{
				fields.ToSource(sb);
			}
			if(properties != null)
			{
				properties.ToSource(sb);
			}
			if (constructors != null)
			{
				constructors.ToSource(sb);
			}
			if (methods != null)
			{
				methods.ToSource(sb);
			}
			if (indexers != null)
			{
				indexers.ToSource(sb);
			}
			if (events != null)
			{
				events.ToSource(sb);
			}
			if (destructors != null)
			{
				destructors.ToSource(sb);
			}

			indent--;
			this.NewLine(sb);
			sb.Append("}");
			this.NewLine(sb);

        }
	
	}
}
